﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Microsoft Corp." file="CreateJobFromXmlCommand.cs">
//   All rights reserved. See License.txt in the project root for license information.
// </copyright>
// 
// --------------------------------------------------------------------------------------------------------------------
namespace HpcSchedulerManagement.HpcSchedulerCommands
{
    using System;

    using Common;

    using HpcSchedulerManagement.HpcSchedulerDataContracts;

    using RestClient;

    public class CreateJobFromXmlCommand : HpcSchedulerCommandBase
    {
        private readonly string hpcClusterName;

        private readonly SchedulerJob job;

        public CreateJobFromXmlCommand(IHpcSchedulerServiceContext serviceContext, string hpcClusterName, SchedulerJob job) : base(serviceContext)
        {
            if (string.IsNullOrEmpty(hpcClusterName))
            {
                throw new ArgumentException("Hpc cluster name must not be null or empty.", "hpcClusterName");
            }

            if (job == null)
            {
                throw new ArgumentNullException("job", "Job must not be null or empty.");
            }

            this.hpcClusterName = hpcClusterName;
            this.job = job;
        }

        protected override RequestContext GetRequestContext()
        {
            return this.CreatePostOperationRequestContext();
        }

        protected override string FormatPath(IHpcSchedulerServiceContext serviceContext)
        {
            return string.Format("{0}/Jobs/JobFile", this.hpcClusterName);
        }

        protected override string FormatBody()
        {
            return XmlHelper.Serialize(this.job);
        }
    }
}